﻿using System;
using System.Collections.Generic;
using System.Web;
using Entity;
using System.Data;
using DbCommon;

namespace Web.frontpage.SignUp.right
{
    /// <summary>
    /// MoreSignUp 的摘要说明
    /// </summary>
    public class MoreSignUp : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //不让浏览器设有缓存
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";
            object stuid = context.Request["STU_CODE"];
            string GRO_NAME = context.Request["GRO_NAME"].ToString();
            string PAR_CONTESTS = context.Request["PAR_CONTESTS"].ToString();
            string GRO_SPECIALTY = context.Request["GRO_SPECIALTY"].ToString();
            string[] StuId = stuid.ToString().Split(' ');
            List<BoParticipants> participants = new List<BoParticipants>();
            for (int i = 0; i < StuId.Length-1; i++)
            {
                BoParticipants model = new BoParticipants();
                model.STU_CODE = StuId[i];
                model.PAR_CONTESTS = PAR_CONTESTS;
                model.GRO_NAME = GRO_NAME;
                participants.Add(model);
            }
            BLL.ParticipantService participantsBll = new BLL.ParticipantService();
            if (participantsBll.InsertGroup(participants, PAR_CONTESTS, GRO_NAME, GRO_SPECIALTY))
            {
               DataTable  table =  participantsBll.GetV_Participant("GRO_NAME = '" + GRO_NAME + "' and PAR_CONTESTS ='" + PAR_CONTESTS + "'");
               string jsonData = JsonHelper.DataTableToJSON(table, "tempTable");
               context.Response.Write(jsonData);
            }
            else
                context.Response.Write("数据出现问题");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}